#include "batchVac.h"
#include "index.h"
#include "options.h"
#include<vector>
#include<sys/stat.h>
#include<sys/types.h>
#include<stdio.h>
#include "test.h"


int main(int argc, char *argv[])
{
    cout<<"\nBonjour \nCommencer à simuler le modele SEIR !"<<endl;

    //Creer un repertoire pour sauvegarder tous les fichiers de resultats
    char comRepertoire[255] = "";
    char nomRepertoire[255] = "Output";
    sprintf(comRepertoire, "%s%s", "mkdir ", nomRepertoire);
    if(system(comRepertoire)) cout <<"Repertoire contenant les fichiers des resultats Output est en train de exister!"<<endl;
    else
        cout<<"Creation du repertoire Output est avec succes!"<<endl;


    //Variable
    char SAUVER[5] = "";
    vector<double> valParSIM, valParVAC;

    //Choisir le type de programme
    int  typePRO = opterTypeProgramme();
    if(typePRO == 1){
        valParSIM = initialervalParSIM(argc, argv);
        valParSIM = changerValInitParmSIM(valParSIM);

        //Initialiser les nombres de personnes de chaque groupe
        double graine = valParSIM[igraine];


        int typeSIM = valParSIM[inbVille];
        SAUVER[0] = 'Y';
        srand(250023456);
       // simulerSEIR_00(valParSIM,SAUVER,NULL,NULL,NULL);
        int nbVill = valParSIM[inbVille];


        double *phi  = new double[nbVill];
        for(int i = 0; i< nbVill ; i++) {
            phi[i] = valParSIM[iphiMIN];
        }
      //   simulerSEIR_01(valParSIM,SAUVER,NULL, phi, arr_rho);
      //  phi = calculerPhases(1, 3.14, 0.0);
      // double **arr =  calculerTauxCouplage_01(3,0.05);
      //  verifierSYNCH_01_00(valParSIM,3);
       // diviserChronologie(0,9.9,1);
      voirPersiGlobale(valParSIM,100);
/*
        if(typeSIM == 1){
            cout<<"Nombre de villes est egal "<<typeSIM<<" -> Il y a une seule population!"<<endl;
            srand(250023456);
           // simulerSEIR_00(valParSIM,SAUVER,NULL,NULL,NULL);
             simulerSEIR_01(valParSIM,SAUVER,NULL);

        }
        else if(typeSIM > 1){
             int nbVille = typeSIM;
             cout<<"Nombre de villes est egal "<<typeSIM<<" -> Simulation du modele SEIR spatiale!"<<endl;
             cout<<"Parametres speciales: topologie, epsilon (taux de couplage), parametres de synchronie"<<endl;
             int typeTOPO = opterTopologie();
             valParSIM[itopology] = typeTOPO;
             cout<<"Donner la valeur de couplage, epsilon = ";
             double epsilon = donnerChoix();
             valParSIM[iepsilon] = epsilon;
             int typeSYNCH = opterParamPopulation();
             if(typeSYNCH == 1){
                 //villes toutes identiques
                faireSYNCH_identique(valParSIM,SAUVER);
             }
             else if(typeSYNCH == 2){
               //villes de synchronie selon I0 -> S0, E0, R0, N0
                 faireSYNCH_synchronieI0(nbVille,valParSIM,SAUVER);

             }
             else if(typeSYNCH == 3) {
                 //Villes quelconque
                 faireSYNCH_quelconques(nbVille,valParSIM,SAUVER);

             }
             else{
                 cout<<"Il n'y a aucune synchronie!\t"<<endl;
             }
        }

        else if(typeSIM == 0)
        {
            cout<<"Il n'y a aucune simulation!\nAurevoir!"<<endl;
        }
  // finir le type ==1
    */
    }
    else if(typePRO == 2){

        SAUVER[0] = 'Y';
        valParSIM = initialervalParSIM(argc, argv);
        valParSIM = changerValInitParmSIM(valParSIM);

        valParVAC = initialervalParVAC(argc,argv);
        valParVAC = changerValInitParmVAC(valParVAC);
        cout<<"\nSimulation sans vaccination"<<endl;
        simulerSEIR_00(valParSIM,SAUVER,NULL,NULL,NULL);

        cout<<"\nSimulation avec vaccination"<<endl;
        simulerSEIR_00(valParSIM,SAUVER,NULL,&valParVAC,NULL);

    }
    else if(typePRO == 3){

        /*
        valParSIM = initialervalParSIM(argc, argv);
        valParSIM = changerValInitParmSIM(valParSIM);

        valParVAC = initialervalParVAC(argc,argv);
        valParVAC = changerValInitParmVAC(valParVAC);
        verifierEvolVac(valParSIM, valParVAC,20,100,100);
        */
        unit_test_evolVac();
    }
    else if(typePRO == 4){
        SAUVER[0] = 'Y';
        valParSIM = initialervalParSIM(argc, argv);
        valParSIM = changerValInitParmSIM(valParSIM);
        valParSIM[inbVille] = 2;
        valParSIM[itopology] = 2;
        valParSIM[itmax] = 36500;
        //verifierSYNCH_ver03(valParSIM,2000,0.1);
        /*
        verifierSYNCH(valParSIM,100,0.1);
        verifierSYNCH(valParSIM,500,0.1);
        verifierSYNCH(valParSIM,1000,0.1);
        verifierSYNCH(valParSIM,2000,0.1);
        */
        /*
        verifierSYNCH_ver02(valParSIM,100,0.1);
        verifierSYNCH_ver02(valParSIM,500,0.1);
        verifierSYNCH_ver02(valParSIM,1000,0.1);
        verifierSYNCH_ver02(valParSIM,2000,0.1);

        verifierSYNCH_ver03(valParSIM,100,0.1);
        verifierSYNCH_ver03(valParSIM,500,0.1);
        verifierSYNCH_ver03(valParSIM,1000,0.1);
        verifierSYNCH_ver03(valParSIM,2000,0.1);
       */
        verifierSYNCH_ver03(valParSIM,5000,0.1);


        /*
        nodeSEIR SEIRtp;
        vector<nodeSEIR> valSEIR0;
        double extinctionglobal;
        char command[255];

        srand(1000);
        //ville 1
        SEIRtp.t = 0;
        double S01 = 9900; SEIRtp.S = S01;
        double E01 = 0; SEIRtp.E = E01;
        double I01 = 100; SEIRtp.I = I01;
        double R01 = 0; SEIRtp.R = R01;
        double N01 = 10000; SEIRtp.N = N01;
        SEIRtp.event = 0;
        valSEIR0.push_back(SEIRtp);

        //ville 2
        double S02 = 9900,E02 = 0,I02 = 100,R02 = 0,N02 = 10000;

        //file
        FILE * fNbEXTINCTION;
        fNbEXTINCTION = fopen ("Output/data_SYNCH.csv","a+");

        while(I02 <= 10000){
           SEIRtp.t = 0;
           SEIRtp.S = S02; SEIRtp.E = E02; SEIRtp.I = I02; SEIRtp.R = R02; SEIRtp.N = N02;
           SEIRtp.event = 0;
           valSEIR0.push_back(SEIRtp);
           //fonctionner la synchronie
           extinctionglobal =  verifierSYNCH_ver02(1000,valSEIR0,valParSIM,SAUVER);
           sprintf(command, "vill 1 : S01 = %.0f, E01 = %.0f, I01 = %.0f, R01 = %.0f, N01 = %.0f\n",S01,E01,I01,R01,N01);
           fputs (command,fNbEXTINCTION);
           sprintf(command, "vill 2 : S02 = %.0f, E02 = %.0f, I02 = %.0f, R02 = %.0f, N02 = %.0f\n",S02,E02,I02,R02,N02);
           fputs (command,fNbEXTINCTION);
           sprintf(command, "somme d'extinctions globlaes(/1000) = %.1f\n\n",extinctionglobal);
           fputs (command,fNbEXTINCTION);

           I02 = I02 + 500;
           S02 = 10000 - I02;
        }
        fclose(fNbEXTINCTION);
*/

        //verifierSYNCH_ver02(100,2,valParSIM,SAUVER);
        //verifierSYNCH(valParSIM,20,0.1);
        //unit_test_verifier_synchronie();
    }
    else
    {
        cout<<" Programme a fini!"<<endl;
        return 0;
    }

    return 0;
}
